<template>
  <div class="wrapper" ref="warpper">
    <div class="content">
      <slot></slot>
    </div>
  </div>
</template>

<script>
import BScroll from '@better-scroll/core'
import Pullup from '@better-scroll/pull-up'

export default {
  name: 'scroll',
  components:{},
  props: {
    probeType: {
      type: Number,
      default: 0
    },
    pullUpLoad: {
      type: Boolean,
      default: false
    }
  },
  data(){
    return {
      scroll: null
    }
  },
  created(){},
  mounted(){
    BScroll.use(Pullup)
    // 1. 创建 BScroll 对象
    this.scroll = new BScroll(this.$refs.warpper, {
      scrollY: true,
      probeType: this.probeType,
      pullUpLoad: this.pullUpLoad,
      eventPassthrough:  'horizontal' 
    })

  console.log();
    // 2. 监听滚动的位置
    if (this.probeType === 2 || this.probeType === 3) {
      this.scroll.on('scroll', (postions) => {
        // console.log(options)
        this.$emit('scroll', postions)
      })
    }

    // 3. 监听上拉事件
    if (this.pullUpLoad) {
      this.scroll.on('pullingUp', () => {
        this.$emit('pullingUp')
      })
    }

  },
  watch:{},
  computed:{},
  methods:{
    // 封装 返回顶部方法
    scrollTo(x, y, time=300) {
      this.scroll && this.scroll.scrollTo(x, y, time)
    },
    finishPullUp() {
      this.scroll && this.scroll.finishPullUp()
    },
    refresh() {
      this.scroll && this.scroll.refresh()
    },
    getScrollY() {
      return this.scroll ? this.scroll.y : 0
    }
  },
}
</script>
<style scoped>
</style>